package controllers

import (
	"cangku/models"
	beego "github.com/beego/beego/v2/server/web"
	"github.com/jinzhu/gorm"
)

type MainController struct {
	beego.Controller
}

type Res struct {
	Cre  int
	Msg  string
	Data interface{}
}

func (c *MainController) Add() {
	c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
	name := c.GetString("name")
	address := c.GetString("address")

	//验证
	if name == "" || address == "" {
		c.Data["json"] = Res{500, "仓库、仓库地址、必填项不能为空", nil}
		c.ServeJSON(true)
		return
	}

	data := models.CanKu{
		Model:   gorm.Model{},
		Name:    name,
		Address: address,
	}
	models.DB.Create(&data)
	c.Data["json"] = Res{200, "添加成功", data}
	c.ServeJSON(true)

}
